package com.prism.cluster;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

import com.prism.moodme.data.Data;
import com.prism.moodme.datastore.AccessDataStore;

public class Train {

	public static final String user = "1";
	public static final int centroids = 1;
	public static void main (String[] args) throws SQLException{
		String[] _cond = Data.conditions;
		for(int i=0; i<_cond.length; i++){
				ArrayList<Data> data = AccessDataStore.getData(user, i+1);
				ArrayList<Data> _cents = new ArrayList<Data>();
				Data best;
				for(int j=0; j<10; j++){
					KayMeans kay = new KayMeans(new ClusterSet(centroids, data));
					for(Cluster clust : kay.getNext().getClusters())
						_cents.add(clust.getCentroid());
				}
				ArrayList<Integer> count = new ArrayList<Integer>();
				for(Data curr : _cents){
					count.add(Collections.frequency(_cents, curr));
				}

				Collections.sort(count);
//				System.out.println(count);

//				for(int l=0; l<count.size(); l++){
					int max = count.remove(count.size()-1);
					for(Data curr : _cents){
						if(Collections.frequency(_cents, curr) == max){
							best = curr;
							best.setCentroid(true);
							AccessDataStore.updateData(best);
							break;
						}
					}





		}
	}
}
